package net.lab1024.sa.admin.module.business.ai.controller;

import net.lab1024.sa.admin.module.business.ai.entity.AiModelConfigEntity;
import net.lab1024.sa.admin.module.business.ai.model.dto.AiModelConfigDTO;
import net.lab1024.sa.admin.module.business.ai.model.vo.AiModelConfigVO;
import net.lab1024.sa.admin.module.business.ai.service.AiModelConfigService;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/ai/model-config")
public class AiModelConfigController {

    @Autowired
    private AiModelConfigService aiModelConfigService;

    @GetMapping("/{modelName}")
    public ResponseDTO<AiModelConfigVO> getByModelName(@PathVariable String modelName) {
        AiModelConfigEntity entity = aiModelConfigService.getByModelName(modelName);
        return ResponseDTO.ok(AiModelConfigVO.fromEntity(entity));
    }

    @PostMapping("/")
    public ResponseDTO<Void> add(@RequestBody AiModelConfigDTO dto) {
        aiModelConfigService.add(dto);
        return ResponseDTO.ok();
    }

    @PutMapping("/")
    public ResponseDTO<Void> update(@RequestBody AiModelConfigDTO dto) {
        aiModelConfigService.update(dto);
        return ResponseDTO.ok();
    }

    @DeleteMapping("/{id}")
    public ResponseDTO<Void> delete(@PathVariable Long id) {
        aiModelConfigService.delete(id);
        return ResponseDTO.ok();
    }

    @GetMapping("/list")
    public ResponseDTO<List<AiModelConfigVO>> listAll() {
        List<AiModelConfigEntity> list = aiModelConfigService.listAll();
        return ResponseDTO.ok(list.stream().map(AiModelConfigVO::fromEntity).collect(Collectors.toList()));
    }
} 